from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select


class HomePage(BasePage):
    url = "/crm/index.php?m=dynamic&a=index"
    clue_home_locator = (By.LINK_TEXT, '线索')
    customer_home_locator = (By.LINK_TEXT, '客户')
    business_home_locator = (By.LINK_TEXT, '商机')
    product_home_locator = (By.LINK_TEXT, '产品')
    # 财务定位器
    financial_locator = (By.LINK_TEXT, "财务")
    # 任务
    rw_home_locator = (By.XPATH,'/html/body/div[1]/div/div/div[2]/ul[1]/li[5]/a')
    # 知识
    knowledge_locator = (By.LINK_TEXT, '知识')
    #更多
    move_log_locator = (By.CSS_SELECTOR, 'body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul:nth-child(1) > li.dropdown > a')
    # 日志
    log_locator = (By.LINK_TEXT, '日志')
    # 公告管理
    notice_management_locator = (By.LINK_TEXT, '公告管理')
    #工作动态用户
    user_locator = (By.ID, 'field')
    #工作动态查询
    inquire_btn_locator = (By.ID, 'searchBtn')
    #头像
    avatar_locator = (By.XPATH, '/html/body/div[1]/div/div/div[2]/ul[2]/li[6]/a')
    #个人资料
    data_locator = (By.XPATH, '/html/body/div[1]/div/div/div[2]/ul[2]/li[6]/ul/li[3]/a')
    #登录成功
    login_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    # 线索页面
    def clue_home_page(self):
        self.driver.find_element(*self.clue_home_locator).click()

    # 客户页面
    def customer_home_page(self):
        self.driver.find_element(*self.customer_home_locator).click()

    # 商机页面
    def business_home_page(self):
        self.driver.find_element(*self.business_home_locator).click()

    # 产品页面
    def product_home_page(self):
        self.driver.find_element(*self.product_home_locator).click()

    # 财务页面
    def financial_home_page(self):
        self.driver.find_element(*self.financial_locator).click()

    # 任务页面
    def rw_home_page(self):
        self.driver.find_element(*self.rw_home_locator).click()

        # 知识页面
    def knowledge_home_page(self):
        self.driver.find_element(*self.knowledge_locator).click()

    #更多
    def move_page(self):
        self.driver.find_element(*self.move_log_locator).click()


        # 日志页面
    def log_home_page(self):
        self.driver.find_element(*self.log_locator).click()

        # 公告管理
    def notice_management_home_page(self):
        self.driver.find_element(*self.notice_management_locator).click()

    #工作动态用户下拉框第一个
    def dynamic_user_one(self):
        usr =self.driver.find_element(*self.user_locator)
        usr.click()
        select = Select(usr)
        select.select_by_index(0)

    # 工作动态用户下拉框最后一个
    def dynamic_user_last(self):
        usr =self.driver.find_element(*self.user_locator)
        usr.click()
        select = Select(usr)
        select.select_by_index(1)
    #动作动态用户点击查询
    def dynamic_inquire_btn(self):
        self.driver.find_element(*self.inquire_btn_locator).click()

    #点击头像
    def click_avatar(self):
        self.driver.find_element(*self.avatar_locator).click()

    #点击个人资料
    def click_data(self):
        self.driver.find_element(*self.data_locator).click()

    #成功登录文本
    def login_ok(self):
        return self.driver.find_element(*self.login_locator).text
